package com.jingdianjichi;

import lombok.Data;

import java.io.Serializable;
@Data

public class Result<T> implements Serializable {
    private Result() {
    }

    private Boolean success;
    private Integer code;
    private String message;
    private T data;

    public static Result ok() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMesage.SUCCESS);
        return result;

    }

    public static Result ok(Integer resultCode, String resultMessage) {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;

    }

    public static <T> Result ok(Integer resultCode, String resultMessage, T data) {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;

    }

    public static <T> Result ok(T data) {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage(ResultMesage.SUCCESS);
        return result;

    }



    public static Result fail(){
        Result result= new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMesage.ERROR);
        return result;

    }
    public static Result fail(Integer resultCode,String resultMessage){
        Result result= new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;

    }
    public static<T> Result fail(Integer resultCode,String resultMessage,T data){
        Result result= new Result();
        result.setSuccess(true);
        result.setCode(resultCode);
        result.setMessage(resultMessage);
        return result;

    }
    public static<T> Result fail(T data){
        Result result= new Result();
        result.setSuccess(true);
        result.setCode(ResultCode.ERROR);
        result.setMessage(ResultMesage.ERROR);
        return result;

    }

}